﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model;

namespace com.lover.astd.common.logicexe.economy
{
    public class MarketExe : ExeBase
    {
        public MarketExe() { _name = ConfigStrings.S_Market; _readable = ConfigStrings.SR_Market; }
        public override long execute()
        {
            Dictionary<string, string> conf = getConfig();
            if (!conf.ContainsKey(ConfigStrings.enabled) || !conf[ConfigStrings.enabled].ToLower().Equals("true")) return next_day();

            bool _notbuy_if_fail = false;
            if(conf.ContainsKey(ConfigStrings.notbuy_iffail)) _notbuy_if_fail = conf[ConfigStrings.notbuy_iffail].ToLower().Equals("true");
            string configstr = "";
            if(conf.ContainsKey(ConfigStrings.items)) configstr = conf[ConfigStrings.items];

            MiscMgr mgr = ServiceFactory.getMiscManager();
            int silver_available = _user.Silver; // 市集不保留银币
            int gold_available = getGoldAvailable();
            int result = mgr.handleMarketInfo(_proto, _logger, configstr, _notbuy_if_fail, silver_available, gold_available);
            if (result == 1) return next_hour(); // success
            else if (result == 2) return next_hour(); // no money
            else return next_halfhour();
        }
    }
}
